const formatTime = date => {
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()
  
    return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
   // return [hour, minute].map(formatNumber).join(':')
  }
  
  const formatNumber = n => {
    n = n.toString()
    return n[1] ? n : '0' + n
  }
  
  //得到时间格式!!!!!!
  const formatDate = date => {
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    return [year, month, day].map(formatNumber).join('-')
  
  }
  //todate默认参数是当前日期，可以传入对应时间 todate格式为2018-10-05
 const  getDates=(days, todate)=> {
    var dateArry = [];
    for (var i = 6; i >=0 ; i--) {
      var dateObj = dateBefore(todate, i);
      dateArry.push(dateObj)
    }
    return dateArry;
  }
 const dateBefore= (dates, before)=> {
    let dateObj = [];
    let show_day = new Array('周日', '周一', '周二', '周三', '周四', '周五', '周六');
    let date = new Date(dates);
    date.setDate(date.getDate() - before);
    let day = date.getDay();
    let month = ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : date.getMonth() + 1);
    let dayFormate = (date.getDate() < 10 ? ("0" + date.getDate()) : date.getDate());
    dateObj = month + '/' + dayFormate+"\n"+show_day[day];
    return dateObj;
  }
  
 export{
    formatTime,
    formatDate,
    getDates
  }
  